from django.db import models
from datetime import datetime
# Create your models here.
# orm就是将添加数据库中的语句转变成类的方式添加，从而提升开发效率
class Book(models.Model):
    # id = models.BigAutoField(primary_key=True)
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=20)
    pub_time = models.DateTimeField(auto_now_add=True)
    price = models.FloatField(default=0)
    class Meta:
        db_table = 'book_table'
        ordering = ['-pub_time', 'price']
# 所有配置完成后执行如下命令
# 1、 python manage.py makemigrations 执行命令生成迁移脚本文件
# 2.python manage.py migrate将文件导入数据库
# 模型常见的Field
class Author(models.Model):
    is_active = models.BooleanField()
    username = models.CharField(max_length=200)
    date_joined = models.DateTimeField(auto_now_add=True)
    email = models.EmailField()
    visit_count = models.IntegerField()
    # profile = models.CharField(max_length=200)
    profile = models.TextField()
    website = models.URLField()
class Tag(models.Model):
    # db_column = 'tag_name'修改字段名
    name = models.CharField(max_length=200,db_column='tag_name',unique=True)
    create_time = models.DateTimeField(default=datetime.now)
    # 1.状态可用  2.状态不可用
    # status = models.SmallIntegerField(default=1)
    # status = models.IntegerField(choices=((1,'可用'),(2,'不可用')))